<!DOCTYPE html>
<html>
<head>
	<title>数据字典定义页面</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
	    var path = window.document.location.href;
		var pathName = window.document.location.pathname;
		var hostPath = path.substring(0, path.indexOf(pathName));
		var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
		document.write('<scr' + 'ipt src="' + projectName + '/js/html/header.js"></scr'+'ipt>');
    </script>
</head>
<body>
	<table id="dg" style="width:auto;height:auto">
		<thead>
			<tr>
				<th field="id" data-options="hidden:true">ID</th>
				<th field="dataType" 	width="100" align="right"
					data-options="
					sortable:true,
					remoteSort:false,
					editor:{
						type:'easyui-combobox',
						options:{
							required:true
						}
					}">字典类型</th>
				<th field="dataTypeName" 	width="100" align="right"
					data-options="
					sortable:true,
					remoteSort:false,
					editor:{
						type:'validatebox',
						options:{
							required:true
						}
					}">字典类型名称</th>
				<th field="dataNo" 	width="100" align="right"
					data-options="
					sortable:true,
					remoteSort:false,
					editor:{
						type:'validatebox',
						options:{
							required:true
						}
					}">字典码值</th>
				<th field="dataName" 	width="100" align="right"
					data-options="
					sortable:true,
					remoteSort:false,
					editor:{
						type:'validatebox',
						options:{
							required:true
						}
					}">字典名称</th>
			</tr>
		</thead>
	</table>
	<div id="dg-buttons" style="height:auto">
		<div style="margin-bottom:5px">
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" 	onclick="dlgAdd()">新增</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" 	onclick="dlgRemove()">删除</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" 	onclick="dlgEdit()">修改</a>
		</div>
		<div>
			<span>字典类型:</span>
			<input type="text" id="dataType" name="dataType" class="easyui-validatebox" />
			<span>字典类型名称:</span>
			<input type="text" id="dataTypeName" name="dataTypeName" class="easyui-validatebox" />
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="dataDicDbQuery()">查询数据库</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="dataDicCacheQuery()">查询缓存</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" onclick="reloadDataDic()">刷新缓存</a>
		</div>
	</div>
	
	<div id="dlg-buttons">
    	<a href="javascript:dlgSave()" class="easyui-linkbutton" iconCls="icon-ok">保存</a> 
        <a href="javascript:dlgClose()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
    </div>
	
	<div id="dlg" class="easyui-dialog" closed="true" style="width:730px;height:280px;padding:10px 10px;" buttons="#dlg-buttons">
            <form method="post" id="fm">
                <table cellspacing="8px;">
                	<td><input id="id" name="id" style="display:none" required="true" ></td>
                    <tr>
                        <td>字典类型：</td>
                        <td>
                        	<input type="text" id="dataType" name="dataType"
                        	class="easyui-validatebox" required="true" >&nbsp;
                        	<span style="color: red">*</span>
                        </td>
                        <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                        <td>字典类型名称：</td>
                        <td>
                        	<input type="text" id="dataTypeName" name="dataTypeName"
                            class="easyui-validatebox" required="true" />&nbsp;
                            <span style="color: red">*</span>
                        </td>
                    </tr>
                    <tr>
                        <td>字典码值：</td>
                        <td><input type="text" id="dataNo" name="dataNo"
                            class="easyui-validatebox" required="true" />&nbsp;
							<span style="color: red">*</span>
                        </td>
                        <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                        <td>字典名称：</td>
                        <td><input type="text" id="dataName" name="dataName"
                            class="easyui-validatebox" required="true" />&nbsp;
							<span style="color: red">*</span>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
	<script>
		var initd = {
			queryDataURL:"/datadic/query",//查询URL
			saveDataURL:"/datadic/save",//保存URL
			removeDataURL:"/datadic/remove",//删除URL
			reloadDataURL:"/datadic/reload",
			dg:$('#dg'),
			dataDicList:{'ORG':['orgId'],'10':['dimNo','dimNo']}//需加载的 DATADIC 字典名+作用的字段名
		};

		
		
		function dataDicDbQuery(){
			initd.dg.datagrid('options').url = projectName+initd.queryDataURL;
			var queryParams = initd.dg.datagrid('options').queryParams;
			queryParams['queryType']='db';
			initd.dg.datagrid('options').queryParams=queryParams;
			dgop.find();
		}
		
		function dataDicCacheQuery(){
			initd.dg.datagrid('options').url = projectName+initd.queryDataURL;
			var queryParams = initd.dg.datagrid('options').queryParams;
			queryParams['queryType']='cache';
			initd.dg.datagrid('options').queryParams=queryParams;
			dgop.find();
		}

		
		function reloadDataDic(){
			var queryParams = initd.dg.datagrid('options').queryParams;
			//组织查询条件
			var queryField = $("#dg-buttons").find("input");
			for(var i = 0; i < queryField.length; i++){
				var temp = queryField[i].id;
				if(!jQuery.isEmptyObject(temp)){
					var className = $("#dg-buttons").find("#"+temp).attr("class");
					if(!jQuery.isEmptyObject(className)){
						if(className.indexOf("combobox") > 0){//如果是combobox控件则用getValues函数取值，其他则用val取值
							queryParams[temp]=$("#dg-buttons").find("#"+temp).combobox('getValue');
						}else{
							queryParams[temp]=$("#dg-buttons").find("#"+temp).val();
						}
					}
				}
			}
			$.ajax({
				type:"POST",
				url:projectName+initd.reloadDataURL,
				data:{
					'dataType':queryParams['dataType']
				},
				dataType : "json",
				success:function(data){
					if(!data.success){
				    	alert(data.message);
				    	return;
				    }
		            if(data != null){
						initd.dg.datagrid('reload');
		            }
				}
			});
		}
		
	</script>
</body>
</html>

